import { get, post, put, del } from '@/utils/request';

// 定义接口类型
export interface ScheduleParams {
  teamId: number;
  rule: 'ROTATION' | 'FIXED';
  rotationType?: 'DAILY' | 'WEEKLY' | 'MONTHLY';
  startTime: string;
  endTime?: string;
  members: number[];
  name: string;
  description?: string;
}

export interface ScheduleInfo {
  id: number;
  teamId: number;
  rule: 'ROTATION' | 'FIXED';
  rotationType: 'DAILY' | 'WEEKLY' | 'MONTHLY';
  startTime: string;
  endTime: string;
  members: Array<{
    id: number;
    username: string;
    realName: string;
    avatar: string;
  }>;
  name: string;
  description: string;
  createTime: string;
  updateTime: string;
}

// 获取排班列表
export function getScheduleList(params: any) {
  return get<{
    total: number;
    list: ScheduleInfo[];
  }>('/schedule/list', params);
}

// 获取排班详情
export function getScheduleDetail(id: number) {
  return get<ScheduleInfo>(`/schedule/${id}`);
}

// 创建排班
export function createSchedule(data: ScheduleParams) {
  return post<number>('/schedule/create', data);
}

// 更新排班
export function updateSchedule(id: number, data: ScheduleParams) {
  return put<boolean>(`/schedule/${id}`, data);
}

// 删除排班
export function deleteSchedule(id: number) {
  return del<boolean>(`/schedule/${id}`);
}

// 获取当前值班人员
export function getCurrentOnDuty(teamId?: number) {
  return get<Array<{
    id: number;
    username: string;
    realName: string;
    avatar: string;
    phone: string;
    email: string;
    scheduleId: number;
    scheduleName: string;
  }>>('/schedule/current-on-duty', { teamId });
}

// 导出排班表为ICS
export function exportScheduleICS(id: number) {
  return get('/schedule/export-ics', { id }, { responseType: 'blob' });
}

// 获取排班日历数据
export function getScheduleCalendar(params: {
  startDate: string;
  endDate: string;
  teamId?: number;
}) {
  return get('/schedule/calendar', params);
} 